package com.qing.cheng.controller;


import com.qing.cheng.dto.ExceptionRes;
import com.qing.cheng.dto.ResponseMessage;
import com.qing.cheng.dto.SuccessRes;
import com.qing.cheng.service.UserInfoService;
import com.qing.cheng.util.SessionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户信息
 */

@RestController
@RequestMapping("/userinfo")
public class UserInfoController {

    private final UserInfoService userInfoService;

    Logger log = LoggerFactory.getLogger(UserInfoController.class);

    public UserInfoController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }

    /**
     * 获取当前用户下的所有学生
     */
    @RequestMapping("/listAllStudent")
    public ResponseMessage listAllStudent(HttpServletRequest request) {
        try {
            return SuccessRes.success(userInfoService.listAllStudent(SessionUtil.getUserId(request)));
        }catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return    ExceptionRes.Fail(e);
        }
    }

    /**
     * 获取当前学生的班级id所有可选课程
     */
    @RequestMapping("/listAllCourse/{stuId}")
    public ResponseMessage listAllCourse(@PathVariable Integer stuId) {
        try {
            return SuccessRes.success(userInfoService.listAllCourse(stuId));
        }catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
            return ExceptionRes.Fail(e);
        }
    }


}
